// pages/moreservice/shared_parking/shared_parking.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    current:0,
    attitude:true,
    time: true,
    efficiency: true,
    environment:true,
    professional:true,
    imgList: [],
    userStars: [
     "../../static/icon/stars.png",
     "../../static/icon/stars.png",
     "../../static/icon/stars.png",
     "../../static/icon/stars.png",
     "../../static/icon/stars.png"
    ],
    wjxScore: 5,
    max: 200, //最多字数 
  },
   // 星星点击事件
   starTap: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index; // 获取当前点击的是第几颗星星
    var tempUserStars = this.data.userStars; // 暂存星星数组
    var len = tempUserStars.length; // 获取星星数组的长度
    for (var i = 0; i < len; i++) {
      if (i <= index) { // 小于等于index的是满心
        tempUserStars[i] = "../../static/icon/stars.png";
        that.setData({
          wjxScore:i+1,
        })
      } else { // 其他是空心
        tempUserStars[i] =  "../../static/icon/emptystars.png";
      }
    }
    // 重新赋值就可以显示了
    that.setData({
      userStars: tempUserStars
    })
  },
  // 标签
  label:function(e){
    console.log(e)
    var that = this;
    that.setData({
      attitude:!e.currentTarget.dataset.index
    })
  },
   label1: function (e) {
    console.log(e)
    var that = this;
    that.setData({
      time: !e.currentTarget.dataset.index
    })
  },
   label2: function (e) {
     console.log(e)
     var that = this;
     that.setData({
       efficiency: !e.currentTarget.dataset.index
     })
   },
    label3: function (e) {
     console.log(e)
     var that = this;
     that.setData({
       environment: !e.currentTarget.dataset.index
     })
   },
    label4: function (e) {
      console.log(e)
      var that = this;
      that.setData({
        professional: !e.currentTarget.dataset.index
      })
    },
  ChooseImage() {
    wx.chooseImage({
      count: 4, //默认9
      sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album'], //从相册选择
      success: (res) => {
        if (this.data.imgList.length != 0) {
          this.setData({
            imgList: this.data.imgList.concat(res.tempFilePaths)
          })
        } else {
          this.setData({
            imgList: res.tempFilePaths
          })
        }
      }
    });
  },
  ViewImage(e) {
    wx.previewImage({
      urls: this.data.imgList,
      current: e.currentTarget.dataset.url
    });
  },
  DelImg(e) {
    wx.showModal({
      content: '确定要删除这张图片吗？',
      cancelText: '再想想',
      confirmText: '删除',
      success: res => {
        if (res.confirm) {
          this.data.imgList.splice(e.currentTarget.dataset.index, 1);
          this.setData({
            imgList: this.data.imgList
          })
        }
      }
    })
  },
    // 留言
    //字数限制
    inputs: function (e) {
      // 获取输入框的内容
      var value = e.detail.value;
      // 获取输入框内容的长度
      var len = parseInt(value.length);
      //最多字数限制
      if (len > this.data.max) return;
      // 当输入框内容的长度大于最大长度限制（max)时，终止setData()的执行
      this.setData({
        currentWordNumber: len //当前字数
      });
    },
  publish:function(){
    wx.showToast({
      title: '发布',
      duration: 1000
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})